#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;
#define rep(i, a, b) for (int i = (a); i <= (b); i++)
#define per(i, a, b) for (int i = (a); i >= (b); i--)
#define endl '\n'
const int N = 1e6 + 5;

int n, m;
string s, t;
string expr(string& s) {
  s += s;
  int i = 0, j = 1, k = 0;
  while (i < n && j < n && k < n) {
    if (s[i + k] == s[j + k])
      k++;
    else {
      if (s[i + k] < s[j + k])
        j += k + 1;
      else
        i += k + 1;
      if (i == j) i++;
      k = 0;
    }
  }
  return s.substr(min(i, j), n);
}
int main() {
  ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cin >> s >> t;
  n = s.size(), m = t.size();
  if (n != m) {
    cout << "No";
    return 0;
  }
  string t1 = expr(s);
  string t2 = expr(t);
  if (t1 == t2)
    cout << "Yes" << endl << t1;
  else
    cout << "No";
  return 0;
}